﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using S4Store.Persistent;

namespace S4Store.Service
{
    public class Transtion:IDisposable
    {
        public static Transtion NewTranstion()
        {
            return new Transtion();

        }

        public S4StoreDataContext PersistentContext { get; set; }

        public Transtion()
        {
            Init();
        }

        public void Init()
        {
            PersistentContext = new S4StoreDataContext();
        }

        public void Commit()
        {
            PersistentContext.SaveChanges();
        }



        public T Inject<T>(T service) where T : BaseService
        {
            service.SetTranstion(this);
            return service;
        }

        public void Inject<T>(params T[] services) where T : BaseService
        {
            foreach(var service in services)
            {
                Inject(service);
            }
        }

        public void Dispose()
        {
           
        }
    }
}
